﻿using SimWithP3d.Vehicle;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace SimWithP3d.ViewModel
{
    public class MainViewModel : NotifyChanged
    {
        private Timer getAxisTimer;

        private int aileron_Axis;
        public int Aileron_Axis
        {
            get { return aileron_Axis; }
            set { aileron_Axis = value; OnPropertyChanged(new PropertyChangedEventArgs("Aileron_Axis")); }
        }
        private int elevator_Axis;
        public int Elevator_Axis
        {
            get { return elevator_Axis; }
            set { elevator_Axis = value; OnPropertyChanged(new PropertyChangedEventArgs("Elevator_Axis")); }
        }
        private int rudder_Axis;
        public int Rudder_Axis
        {
            get { return rudder_Axis; }
            set { rudder_Axis = value; OnPropertyChanged(new PropertyChangedEventArgs("Rudder_Axis")); }
        }

        private int left_Brake;
        public int Left_Brake
        {
            get { return left_Brake; }
            set { left_Brake = value; OnPropertyChanged(new PropertyChangedEventArgs("Left_Brake")); }
        }

        private int right_Brake;
        public int Right_Brake
        {
            get { return right_Brake; }
            set { right_Brake = value; OnPropertyChanged(new PropertyChangedEventArgs("Right_Brake")); }
        }
        private int throttle;
        public int Throttle
        {
            get { return throttle; }
            set { throttle = value; OnPropertyChanged(new PropertyChangedEventArgs("Throttle")); }
        }

        private int mixture;
        public int Mixture
        {
            get { return mixture; }
            set { mixture = value; OnPropertyChanged(new PropertyChangedEventArgs("Mixture")); }
        }
        private int rudder_Trim;
        public int Rudder_Trim
        {
            get { return rudder_Trim; }
            set { rudder_Trim = value; OnPropertyChanged(new PropertyChangedEventArgs("Rudder_Trim")); }
        }
        private int elevator_Trim;
        public int Elevator_Trim
        {
            get { return elevator_Trim; }
            set { elevator_Trim = value; OnPropertyChanged(new PropertyChangedEventArgs("Elevator_Trim")); }
        }
        private int indicator_min=500;
        /// <summary>
        /// 俯仰配平指示器
        /// </summary>
        public int Indicator_min
        {
            get { return indicator_min; }
            set { indicator_min = value; OnPropertyChanged(new PropertyChangedEventArgs("Indicator_min")); }
        }
        private int indicator_max=2500;
        /// <summary>
        /// 俯仰配平指示器
        /// </summary>
        public int Indicator_max
        {
            get { return indicator_max; }
            set { indicator_max = value; OnPropertyChanged(new PropertyChangedEventArgs("Indicator_max")); }
        }

        private int currenSelectedIndex;
        public int CurrenSelectedIndex
        {
            get { return currenSelectedIndex; }
            set { currenSelectedIndex = value; OnPropertyChanged(new PropertyChangedEventArgs("CurrenSelectedIndex")); }
        }
        public MainViewModel()
        {
            getAxisTimer = new System.Timers.Timer();
            getAxisTimer.Elapsed += GetAxisHander;
            getAxisTimer.Interval = 1000;
            getAxisTimer.Start();
        }
        public void Dispose()
        {
            getAxisTimer.Stop();
            getAxisTimer.Dispose();
        }
        private void GetAxisHander(object sender, ElapsedEventArgs e)
        {
            switch (CurrenSelectedIndex)
            {
                case 0:
                    Aileron_Axis = Pa28.Aileron_Axis.Value;
                    break;
                case 1:
                    Elevator_Axis = Pa28.Elevator_Axis.Value;
                    break;
                case 2:
                    Rudder_Axis = Pa28.Rudder_Axis.Value;
                    break;
                case 3:
                    Left_Brake = Pa28.Left_Brake.Value;
                    break;
                case 4:
                    Right_Brake = Pa28.Right_Brake.Value;
                    break;
                case 5:
                    Left_Brake = Pa28.Left_Brake.Value;
                    break;
                case 6:
                    Right_Brake = Pa28.Right_Brake.Value;
                    break;
                case 7:
                    Throttle = Pa28.Throttle.Value;
                    break;
                case 8:
                    Mixture = Pa28.Mixture.Value;
                    break;
                case 9:
                    Rudder_Trim = Pa28.Rudder_Trim.Value;
                    break;
                case 10:
                    Elevator_Trim = Pa28.Elevator_Trim.Value;
                    break;
                default:
                    break;
            }
        }
    }
}
